package com.example.demo.xkx;

import com.example.demo.entity.Country;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.Assert;

/**
 * @author xkx
 * @date 2018/12/26
 */
@Slf4j
public class Something {

  private static final String FACTORY_BEAN_PREFIX = "&";
  public static void main(String[] args) {
    /*edObserverable server = new edObserverableImpl();

    Observerable userZhang = new User("ZhangSan");
    Observerable userLi = new User("LiSi");
    Observerable userWang = new User("WangWu");

    server.registerObserver(userZhang);
    server.registerObserver(userLi);
    server.registerObserver(userWang);
    ((edObserverableImpl) server).setInfomation("PHP是世界上最好用的语言！");

    System.out.println("----------------------------------------------");
    server.removeObserver(userZhang);
    ((edObserverableImpl) server).setInfomation("JAVA是世界上最好用的语言！");*/
//    Xkx xkx = new Xkx();
//    System.out.println(xkx.getClass().getName());
    // 断言测试
//     assertTest("宫崎骏");
    String name = "&xukaixuan";
    if (name.startsWith(Something.FACTORY_BEAN_PREFIX)) {
      System.out.println(name.length());
      System.out.println(Something.FACTORY_BEAN_PREFIX.length());
      System.out.println(name.substring(-1));
    }
  }

  public static void assertTest(String name) {
    Assert.notNull(name, "'name' must not be null");
    System.out.println(name);
  }

  public static void passWordEncoderTest(String password) {
    PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    String encoded = passwordEncoder.encode(password);
    System.out.println(password+"后的密码: = " +encoded );
    //$2a$10$/69I3trRcZ79vMPCrbquy.kia12t055Yjs/tu4CQ/jpbkP7rgSrHy
    //$2a$10$NeUdD7hvtIoRSnYt/Pr/M.2GqcN5asrnbgx5WYdvkWpn0pJYsDGqa
  }


  @Test
  public void beanUtilsTest() {
    Map<String, Object> map = new HashMap<>();
    map.put("id",1L);
    map.put("name","中国");
    map.put("state","ASIAN");
    Country country = new Country();
    try {
      BeanUtils.populate(country,map);
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
    System.out.println(country);

  }






}
